<template>
  <div class="positionUser-page">
    <MainHead title="师资管理" @change="getPageList()" />
    <el-card class="main-card" shadow="never" v-loading="$store.state.loading">
      <div class="search">
        <div>
          <el-button
            type="primary"
            @click="
              $router.push('/app-vue/school/teacher/teacher-manageme/add')
            "
            >新增师资</el-button
          >
          <Imports
            style="margin: 0 10px"
            url="/djy-chuxin/chuxin/admin/lecturer/saveByExc"
            @change="imporeChange"
            btnType=""
            btnText="批量导入"
          />
          <Download
            style="margin-left: 10px"
            url="/fileweb/partyGroup/file/20210715/da0610b5d14145cc8313bfcab4ddbb79.xlsx"
          />
        </div>

        <div>
          <el-input
            style="width: 264px; margin-right: 10px"
            placeholder="请输入"
            prefix-icon="el-icon-search"
            v-model="formData.keyword"
          ></el-input>
          <el-button type="primary" @click="getPageList()">搜索</el-button>
          <Search
            :config="searchConfig"
            @change="searchChange"
            style="margin-left: 10px"
          />
        </div>
      </div>
      <el-table
        :data="tableData"
        style="width: 100%"
        class="page-table"
        height="calc(100vh - 65px - 60px - 30px - 172px - 119px)"
      >
        <el-table-column prop="id" label="师资id"> </el-table-column>
        <el-table-column prop="lecturerName" label="讲师名"> </el-table-column>
        <el-table-column prop="lecturerPic" label="讲师照片">
          <template slot-scope="{ row }">
            <Images :url="row.lecturerPic" />
          </template>
        </el-table-column>
        <el-table-column prop="positionType" label="业务类型">
          <template slot-scope="{ row }">
            {{ row.positionType | positionType }}
          </template>
        </el-table-column>
        <el-table-column prop="contact" label="联系方式"> </el-table-column>
        <el-table-column prop="professionalIdentity" label="职业身份">
        </el-table-column>
        <el-table-column prop="upCount" label="获赞数"> </el-table-column>
        <el-table-column prop="establishmentUnit" label="建库单位">
        </el-table-column>
        <el-table-column prop="propagandaGroup" label="特色宣讲团">
        </el-table-column>
        <el-table-column prop="researchField" label="研究领域或专业特长">
        </el-table-column>
        <el-table-column prop="gmtModified" label="更新时间"> </el-table-column>
        <el-table-column prop="state" label="启用状态">
          <template slot-scope="{ row }">
            {{ row.state == 1 ? "启用" : "停用" }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="110">
          <template slot-scope="{ row }">
            <el-button
              style="padding: 0"
              type="text"
              @click="
                $router.push({
                  path: '/app-vue/school/teacher/teacher-manageme/edit',
                  query: {
                    id: row.id,
                  },
                })
              "
              >修改</el-button
            >
            <el-button style="padding: 0" type="text" @click="stop(row)">{{
              row.state == 0 ? "启用" : "停用"
            }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="footer-page">
        <Page v-model="pageInfo" @change="getPageList()" />
      </div>
    </el-card>
  </div>
</template>
<script>
import Page from "@/components/Page";
import Imports from "@/components/Imports";
import Download from "@/components/Download";
export default {
  components: {
    Page,
    Imports,
    Download,
  },
  data() {
    return {
      tableData: [],
      pageInfo: {
        pageNo: 1,
        pageSize: 10,
        total: 0,
      },
      formData: {},
      searchConfig: {
        lecturerName: {
          name: "讲师姓名",
          type: "input",
          placeholder: "请输入讲师姓名",
        },
        positionType: {
          name: "业务类型",
          type: "select",
          placeholder: "选择业务类型",
          data: [
            {
              label: "政治理论教育",
              value: 1,
            },
            {
              label: "党性教育",
              value: 2,
            },
            {
              label: "党的宗旨教育",
              value: 3,
            },
            {
              label: "知识技能教育",
              value: 4,
            },
            {
              label: "革命传统教育",
              value: 5,
            },
            {
              label: "政治教育和政治训练",
              value: 6,
            },
            {
              label: "形势政策教育",
              value: 7,
            },
            {
              label: "理想信念教育",
              value: 8,
            },
            {
              label: "政治理论学习",
              value: 9,
            },
          ],
        },
        establishmentUnit: {
          name: "关联建库单位",
          type: "select",
          placeholder: "选择关联建库单位",
          data: [
            {
              label: "南湖区",
              value: "南湖区",
            },
            {
              label: "秀洲区",
              value: "秀洲区",
            },
            {
              label: "嘉善县",
              value: "嘉善县",
            },
            {
              label: "平湖市",
              value: "平湖市",
            },
            {
              label: "海盐县",
              value: "海盐县",
            },
            {
              label: "海宁市",
              value: "海宁市",
            },
            {
              label: "桐乡市",
              value: "桐乡市",
            },
            {
              label: "嘉兴经济技术开发区",
              value: "嘉兴经济技术开发区",
            },
            {
              label: "嘉兴港区",
              value: "嘉兴港区",
            },
            {
              label: "市直机关工委",
              value: "市直机关工委",
            },
            {
              label: "教育局党委",
              value: "教育局党委",
            },
            {
              label: "交通局党委",
              value: "交通局党委",
            },
            {
              label: "建设局党委",
              value: "建设局党委",
            },
            {
              label: "卫健委",
              value: "卫健委",
            },
            {
              label: "国资委",
              value: "国资委",
            },
            {
              label: "嘉兴学院党委",
              value: "嘉兴学院党委",
            },
          ],
        },
        propagandaGroup: {
          name: "特色宣讲团",
          type: "select",
          placeholder: "选择特色宣讲团",
          data: [
            {
              label: "革命红色宣讲组",
              value: "革命红色宣讲组",
            },
            {
              label: "经济蓝色宣讲组",
              value: "经济蓝色宣讲组",
            },
            {
              label: "生活金色宣讲组",
              value: "生活金色宣讲组",
            },
            {
              label: "文化青色宣讲组",
              value: "文化青色宣讲组",
            },
            {
              label: "生态绿色宣讲组",
              value: "生态绿色宣讲组",
            },
            {
              label: "红船精神宣讲组",
              value: "红船精神宣讲组",
            },
            {
              label: "红船银晖宣讲组",
              value: "红船银晖宣讲组",
            },
            {
              label: "红船青年宣讲组",
              value: "红船青年宣讲组",
            },
            {
              label: "红船女儿宣讲组",
              value: "红船女儿宣讲组",
            },
          ],
        },
        researchField: {
          name: "研究领域或专业专长",
          type: "input",
          placeholder: "请输入研究领域或专业专长",
        },
        state: {
          name: "启用状态",
          type: "select",
          placeholder: "选择状态",
          data: [
            {
              label: "已启用",
              value: 1,
            },
            {
              label: "已停用",
              value: 0,
            },
          ],
        },
      },
      searchForm: {},
    };
  },
  created() {
    this.getPageList();
  },
  methods: {
    searchChange(search) {
      this.searchForm = search;
      this.pageInfo.pageNo = 1;
      this.getPageList();
    },
    getPageList() {
      const { pageNo, pageSize } = this.pageInfo;
      this.$Ajax(
        "/chuxin/admin/lecturer/list",
        "get",
        {
          page: pageNo,
          limit: pageSize,
          ...this.formData,
          ...this.searchForm,
        },
        (res) => {
          this.tableData = res.data.list;
          this.pageInfo.total = res.data.totalCount;
        }
      );
    },

    stop(row) {
      this.$alert("<div>确定该操作吗？</div>", "提示", {
        type: "warning",
        dangerouslyUseHTMLString: true,
        showCancelButton: true,
      }).then(() => {
        this.$Ajax(
          "/chuxin/admin/lecturer/enableDeactivation",
          "post",
          {
            id: row.id,
            state: row.state == 1 ? 0 : 1,
          },
          (res) => {
            this.$message.success(res.msg);
            this.getPageList();
          }
        );
      });
    },

    imporeChange(res) {
      if (res.code === 0) {
        this.$message.success(res.msg);
        this.getPageList();
      } else {
        this.$message.success(res.msg);
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.positionUser-page {
  .title {
    display: flex;
    // justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    h2 {
      font-size: 24px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #1c1d1d;
      margin: 0;
    }
  }

  .search {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
  }

  .footer-page {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 24px 0 0 0;
  }
}
</style>
